/**
 * Created by Administrator on 2016/3/8.
 */

//首页js代码
(function(){

	var newestHtml = $("#newest-template").html();
	var newestTpl= Handlebars.compile(newestHtml);

	var invsetorsHtml = $("#invsetors-template").html();
	var invsetorsTpl= Handlebars.compile(invsetorsHtml);

	var investorgHtml = $("#investorg-template").html();
	var investorgTpl= Handlebars.compile(investorgHtml);

	var render = function(){
		$.get('/lt/project/newest',function(data){
			if(!data.result) {
				data.data.forEach(function(v){
					if(v.introduce.length >21){
						v.introduce =  v.introduce.substr(0, 20)+"...";
					}
				});
				$(".obj-list").html(newestTpl(data));
			}
		});
		$.get('/lt/investor/hotest', function(data){
			if(!data.result){
				$(".investors-list").html(invsetorsTpl(data))
			}
		});
		$.get('/lt/investorg/hotest',function(data){
			if(!data.result){
				$(".orz-list").html(investorgTpl(data))
			}
		});
		$.get('/lt/viewpoint/newest',function(data){
			console.log(data.data);
			if(!data.result){
				switch (data.data.length){
					case 1:
					case 2:
					case 3:
					
					case 4:
					default:
						var viewpoint1 = "<img src='"+data.data[0].logoUrl+"'><p><a href=''>"+data.data[0].title+"<span>"+data.data[0].createTime+"</span></a><a href=''>"+data.data[1].title+"<span>"+data.data[1].createTime+"</span></a></p>";
						$(".inform-list:first-child").html(viewpoint1);
						var viewpoint2 =  "<img src='"+data.data[1].logoUrl+"'><p><a href=''>"+data.data[2].title+"<span>"+data.data[2].createTime+"</span></a><a href''>"+data.data[3].title+"<span>"+data.data[3].createTime+"</span></a></p>";
						$(".inform-list:last-child").html(viewpoint2);
						break;
				}

			}
		});
		$.get('/lt/college/newest', function(data){
			console.log(data.data);
			if(!data.result){
				if(data.data[0].content > 21){
					data.data[0].content = data.data[0].content.substr(0, 20)+"...";
				}
				switch (data.data.length){
					case 0:
					case 1:
					case 2:
					case 3:
					default:
						var collegeHtml = "<img src='"+data.data[0].logoUrl+"' height=170 width=170><div><a href=''>"+data.data[0]
							.title+"</a><p>"+data.data[0].content +"<span></br>"+data.data[0].createTime+"</span></p></div>";
						$(".inform-list-two:first-child").html(collegeHtml);
						var collegeHtml2 = "<img src='images/school_list-icon.png' /> <a href='' class='inform-show-a'>"+data.data[1].title+"<span>"+data.data[1].createTime+"</span></a>";
						var collegeHtml3 = "<img src='images/school_list-icon.png' /> <a href='' class='inform-show-a'>"+data.data[2].title+"<span>"+data.data[2].createTime+"</span></a>";
						$(".college-two").html(collegeHtml2);
						$(".inform-list-two:last-child").html(collegeHtml3);
						break;
				}

			}
		});
	};
	render();
})(jQuery);

$(".pre").on("click",function(){
	var $parent, $div;
	$parent = $(this).parent().parent().attr("class");
	if($parent == "latest-obj") {
		$div = $(".obj-list > div:nth-child(1)").remove();
		$(".obj-list").append($div);
	} else {
		$div = $(".orz-list > div:nth-child(1)").remove();
		$(".orz-list").append($div);
	}
});

$(".next").on("click",function(){
	var $parent, $div;
	$parent = $(this).parent().parent().attr("class");
	if($parent == "latest-obj") {
		$div = $(".obj-list > div:last-child").remove();
		$(".obj-list").prepend($div);
	} else {
		$div = $(".orz-list > div:last-child").remove();
		console.log($div);
		$(".orz-list").prepend($div);
	}
});